﻿package com.wandian.view.mediator.account
{
	import com.wandian.controller.AccountCommand;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.model.InRoomPlayerDataProxy;
	import com.wandian.model.SwfDataProxy;
	import com.wandian.model.vo.HonorVo;
	import com.wandian.model.vo.PlayerVo;
	import com.wandian.model.vo.RoomVo;
	import com.wandian.util.CLZButton;
	import com.wandian.util.CLZLlistScrollPanel;
	import com.wandian.util.CLZLoadingData;
	import com.wandian.util.CLZTabBar;
	import com.wandian.util.GlowFilterManage;
	import com.wandian.util.GolbalTimer;
	import com.wandian.view.components.ui.AddBtn;
	import com.wandian.view.components.ui.HonorInfoMc;
	import com.wandian.view.components.ui.MaskTipPanel;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import org.puremvc.as3.interfaces.*;
	import org.puremvc.as3.patterns.mediator.*;
	/**  
	 * 道成就礼品
	 * @author long
	 * @QQ 108232706
	 * @version 1.0   
	 */ 
    public class HonorMediator extends Mediator
    {
        private var _tabBar:CLZTabBar;
        private var _arrData:Array;
        private var _global:GameData;
        private var _contenMc:Sprite;
        private var _playerVo:PlayerVo;
        private var _honorInfoMc:HonorInfoMc;
        public static const NAME:String = "HonorMediator";

        public function HonorMediator(param1:Object = null, param2:PlayerVo = null)
        {
            this._global = GameData.getInstance();
            this._contenMc = new Sprite();
            this._honorInfoMc = new HonorInfoMc();
            this._playerVo = param2;
            super(NAME, param1);
            return;
        }

        override public function onRegister() : void
        {
            this.init();
            this.mcAchievement.addChild(this._contenMc);
            this._contenMc.x = 23;
            this._contenMc.y = 75;
            return;
        }

        private function init() : void
        {
            var _loc_1:Array = [[this.mcAchievement.goldPrize_btn, GameData.tip["GOLD_PRIZE"]], [this.mcAchievement.silverMedal_btn, GameData.tip["SILVERMEDAL"]], [this.mcAchievement.bronzeMedal_btn, GameData.tip["BRONZEMEDAL"]]];
            this._tabBar = new CLZTabBar(_loc_1);
            var _loc_2:int = 0;
            while (_loc_2 < _loc_1.length)
            {
                
                _loc_1[_loc_2][0].addEventListener(Event.CHANGE, this.changeTabBarHandler);
                _loc_2 = _loc_2 + 1;
            }
            this.sendNotification(CLZNoticeName.MY_HONOR_REQ, this._playerVo.userid);
            CLZLoadingData.show(this._contenMc, 723, 365);
            return;
        }

        private function changeTabBarHandler(event:Event) : void
        {
            switch(event.target.name)
            {
                case "goldPrize_btn":
                {
                    this.sortHonorHandler(this._arrData[0], 1);
                    break;
                }
                case "silverMedal_btn":
                {
                    this.sortHonorHandler(this._arrData[1], 2);
                    break;
                }
                case "bronzeMedal_btn":
                {
                    this.sortHonorHandler(this._arrData[2], 3);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

        private function sortHonorHandler(param1:Array, param2:int) : void
        {
            var _loc_10:HonorVo = null;
            var _loc_11:int = 0;
            var _loc_12:HonorVo = null;
            var _loc_3:* = GameData.getHonorByType(param2);
            var _loc_4:Array = [];
            var _loc_5:Array = [];
            var _loc_6:Array = [];
            var _loc_7:* = _loc_3.length;
            var _loc_8:int = 0;
            while (_loc_8 < _loc_7)
            {
                
                _loc_10 = _loc_3[_loc_8] as HonorVo;
                _loc_11 = 0;
                while (_loc_11 < param1.length)
                {
                    
                    _loc_12 = param1[_loc_11] as HonorVo;
                    if (_loc_10.pcate == _loc_12.pcate)
                    {
                    }
                    if (_loc_10.pframe == _loc_12.pframe)
                    {
                        _loc_10.isGet = true;
                        _loc_10.time = _loc_12.time;
                        break;
                    }
                    _loc_11 = _loc_11 + 1;
                }
                if (_loc_10.isGet)
                {
                    _loc_4.unshift(_loc_10);
                }
                else if (this._global.userInfo.userVo.level < _loc_10.targetlevel)
                {
                    _loc_6.push(_loc_10);
                }
                else
                {
                    _loc_5.push(_loc_10);
                }
                _loc_8 = _loc_8 + 1;
            }
            var _loc_9:* = GameData.sortMinToMaxArray(_loc_4, "targetlevel");
            _loc_9 = _loc_9.concat(GameData.sortMinToMaxArray(_loc_5, "targetlevel"));
            _loc_9 = _loc_9.concat(GameData.sortMinToMaxArray(_loc_6, "targetlevel"));
            this.showHonorHandler(_loc_9);
            return;
        }

        private function removeHonorHandler() : void
        {
            var _loc_1:CLZLlistScrollPanel = null;
            var _loc_2:MovieClip = null;
            if (this._contenMc != null)
            {
            }
            if (this._contenMc.numChildren >= 1)
            {
                _loc_1 = this._contenMc.removeChildAt(0) as CLZLlistScrollPanel;
                if (_loc_1 != null)
                {
                    if (_loc_1.canvas != null)
                    {
                        while (_loc_1.canvas.numChildren)
                        {
                            
                            _loc_2 = _loc_1.canvas.removeChildAt(0) as MovieClip;
                            this._honorInfoMc.removeHonorInfo(_loc_2);
                            _loc_2 = null;
                        }
                    }
                }
                GameData.removeNumChildre(this._contenMc);
            }
            return;
        }

        private function showHonorHandler(param1:Array) : void
        {
            var _loc_5:MovieClip = null;
            this.removeHonorHandler();
            var _loc_2:* = new CLZLlistScrollPanel(6, 102, 151, 15, 15, 365, 723, -4);
            this._contenMc.addChild(_loc_2);
            _loc_2.y = 10;
            var _loc_3:* = param1.length;
            var _loc_4:int = 0;
            while (_loc_4 < _loc_3)
            {
                
                _loc_5 = GameData.getMovieClip("HonorMc");
                _loc_2.setMc(_loc_5, _loc_4, _loc_3);
                _loc_5.name = "honor" + _loc_4;
                this._honorInfoMc.setHonorInfo(_loc_5, param1[_loc_4]);
                _loc_4 = _loc_4 + 1;
            }
            return;
        }

        override public function listNotificationInterests() : Array
        {
            return [CLZNoticeName.MY_HONOR_RES, CLZNoticeName.CHANGE_ACCOUNT];
        }

        override public function handleNotification(param1:INotification) : void
        {
            var _loc_2:String = null;
            switch(param1.getName())
            {
                case CLZNoticeName.MY_HONOR_RES:
                {
                    CLZLoadingData.hide(this._contenMc);
                    this._arrData = param1.getBody() as Array;
                    _loc_2 = GameData.replaceStrValue(GameData.tip["PLAYER_SUM_HONOR_TIP"], "NUM", this._arrData[0].length + this._arrData[1].length + this._arrData[2].length);
                    _loc_2 = GameData.replaceStrValue(_loc_2, "NUM1", this._arrData[0].length);
                    _loc_2 = GameData.replaceStrValue(_loc_2, "NUM2", this._arrData[1].length);
                    _loc_2 = GameData.replaceStrValue(_loc_2, "NUM3", this._arrData[2].length);
                    if (this._playerVo.userid == this._global.userInfo.userVo.userid)
                    {
                        _loc_2 = GameData.replaceStrValue(_loc_2, "NAME", "");
                    }
                    else
                    {
                        _loc_2 = GameData.replaceStrValue(_loc_2, "NAME", this._playerVo.name);
                    }
                    this.mcAchievement.honorTip_txt.htmlText = _loc_2;
                    this._tabBar.setClickIndex(this.mcAchievement.bronzeMedal_btn);
                    break;
                }
                case CLZNoticeName.CHANGE_ACCOUNT:
                {
                    this.removeHonorHandler();
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

        private function get mcAchievement() : MovieClip
        {
            return viewComponent as MovieClip;
        }

    }
}
